package com.morningstar.qs.api.basic.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

/**
 * Read the XML file to covert to Dom4j format
 * @deprecated
 * @author dchen2
 * 
 */
public class XMLFileUtil extends FileUtil {

	private String fileName;
	private boolean fromClasspath;

	public XMLFileUtil(String fileName, boolean fromClasspath) {
		this.fileName = fileName;
		this.fromClasspath=fromClasspath;
	}


	/**
	 * @deprecated
	 */
	@Override
	
	public void writeFile(Object object) {
		// TODO Auto-generated method stub

	}
	/**
	 * @deprecated
	 */

	@Override
	public Object readFile() throws FileNotFoundException ,IOException{
		SAXReader reader = new SAXReader();
		BufferedInputStream in = null;
		if (fromClasspath)
			in = new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream(fileName));
		else {
			in = new BufferedInputStream(new FileInputStream(fileName));
		}

		try {
			Document document = reader.read(in);
			return document;
		} catch (DocumentException e) {
			throw new IOException(e);
		}
	}

}
